package cn.hj.domain.strategy.service.rule.tree.factory;

import cn.hj.domain.strategy.model.valobj.RuleLogicCheckTypeVO;
import cn.hj.domain.strategy.model.valobj.RuleTreeVO;
import cn.hj.domain.strategy.service.rule.tree.ILogicTreeNode;
import cn.hj.domain.strategy.service.rule.tree.factory.engine.IDecisionTreeEngine;
import cn.hj.domain.strategy.service.rule.tree.factory.engine.impl.DecisionTreeEngine;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * 规则树工厂
 */
@Service
public class DefaultTreeFactory {

    private final Map<String, ILogicTreeNode> logicTreeNodeGroup;


    public DefaultTreeFactory(Map<String, ILogicTreeNode> logicTreeNodeGroup) {
        this.logicTreeNodeGroup = logicTreeNodeGroup;
    }

    /*
     *由决策树工厂管理规则节点的注入和决策树引擎的创建。在使用的时候，可以通过 openLogicTree 方法获取执行器。执行器提供了规则的执行操作。
     */
    public IDecisionTreeEngine openLogicTree(RuleTreeVO ruleTreeVO) {
        return new DecisionTreeEngine(logicTreeNodeGroup, ruleTreeVO);
    }


    /**
     * 决策树个动作实习
     */
    @Data
    @Builder
    @AllArgsConstructor
    @NoArgsConstructor
    public static class TreeActionEntity {

        private RuleLogicCheckTypeVO ruleLogicCheckType;

        private StrategyAwardVO strategyAwardVO;
    }

    @Data
    @Builder
    @AllArgsConstructor
    @NoArgsConstructor
    public static class StrategyAwardVO {

        /**
         * 抽奖奖品ID - 内部流转使用
         */
        private Integer awardId;

        /**
         * 抽奖奖品规则
         */
        private String awardRuleValue;
    }

}
